card_list = []

def welcome():
    print("*" * 50)
    print("欢迎使用【名片管理系统】\n\r")

    print("您可以输入以下命令")

    print("[1] 新建名片")
    print("[2] 查看名片")
    print("[3] 查询名片\r\n")
    print("[0] 退出系统")
    print("*" * 50)

def new_card():
    name = input("姓名：")
    age = input("年龄：")
    qq = input("QQ：")
    card_list.append({
        "name":name,
        "age":age,
        "qq":qq
    })
    print("名片添加成功")

def view_card():
    if len(card_list) == 0:
        print("没有名片，请添加后查看")
    else:
        for name in ["姓名","年龄","QQ"]:
            print(name,end="\t\t")
        print()
        print("="*50)
        for card in card_list:
            print("%s\t\t%s\t\t%s\t\t" % (card["name"],card["age"],card["qq"]))

def search_card():
    name = input("输入您要查找的姓名")
    for card in card_list:
        if card["name"] == name:
            print("找到了：%s\r\n" % card["name"])
            before_operate(card)
            break
    else:
        print("您要查找的人不在名片管理系统中")

def before_operate(find_card):
    oper_name = input("请选择后续操作：【1】删除    【2】修改   【】返回上一个操作")
    if oper_name == "1":
        card_list.remove(find_card)
        print("删除成功")
    elif oper_name == "2":
        find_card["name"] = _input("姓名",find_card["name"])
        find_card["age"] = _input("年龄",find_card["age"])
        find_card["qq"] = _input("QQ",find_card["qq"])


def _input(mes,val):
    input_val = input(mes)
    if len(input_val) == 0:
        return val
    else:
        return input_val
